package com.learn.spring.registrar;

import com.learn.spring.bean.Dog;
import com.learn.spring.bean.Person;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author wangxing
 * @version 2020/6/12 13:32 Administrator
 * 通过@Import的 ImportBeanDefinitionRegister导入组件  (可以指定bean的名称)
 */
public class TempBeanRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        RootBeanDefinition dog = new RootBeanDefinition(Dog.class);
        RootBeanDefinition person = new RootBeanDefinition(Person.class);
        registry.registerBeanDefinition("dogImport", dog);
        registry.registerBeanDefinition("personImport", person);
    }
}
